package com.authorder.controller;


import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author zzq
 * @since 2021-08-24
 */
@RestController
public class TUserController {

    @GetMapping(value = "/o1")
    // @PreAuthorize("hasAuth ority('p1')")//拥有p1权限方可访问此url
    public Object r1(HttpServletRequest request) {
        //获取用户身份信息
        //UserVO userDTO = (UserVO) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        String header = request.getHeader("Authorization");
        String token = header.replace("Bearer ", "");
        Claims body = Jwts.parser().setSigningKey("uaa123".getBytes(StandardCharsets.UTF_8)).parseClaimsJws(token).getBody();
        return body;
    }

    @GetMapping(value = "/o2")
    // @PreAuthorize("hasAuth ority('p1')")//拥有p1权限方可访问此url
    public String r2() {
        return LocalDateTime.now().toString();
    }


}
